package cn.echoidea.app;

import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.log.Log;
import org.nutz.log.Logs;

import com.jfinal.kit.StringKit;

public class SaePropProxy extends PropertiesProxy {
	Log log = Logs.get();

	/**
	 * 为了能够根据运行期来判断是在本地还是sae环境下
	 * 
	 * @param key
	 * @return
	 */
	public String getDbConfig(String key) {
		// if (isLocal) {
		// jdbcUrl = getProperty("dev.jdbcUrl");
		// user = getProperty("dev.user");
		// password = getProperty("dev.password");
		// } else {
		// jdbcUrl = getProperty("db.jdbcUrl");
		// user = getProperty("db.user");
		// password = getProperty("db.password");
		// }
		//
		String prefix = "";
		if (isLocal) {
			prefix = "dev.";
		} else {
			prefix = "db.";
		}
		return super.get(prefix + key);
	}

	private boolean isLocal = isDevMode();

	private boolean isDevMode() {

		String osName = System.getProperty("os.name"); // 电脑系统名称
		// 坑爹，这里用户名为null
		boolean is = StringKit.notBlank(osName)
				&& osName.indexOf("Windows") != -1;
		if (log.isErrorEnabled()) {
			log.error("isDevMode=[" + is + "]");
		}

		return is;
	}

}
